package com.niuke;

/**
 * @ClassName : step
 * @Author : kele
 * @Date: 2023/4/2 12:38
 * @Description :
 */
public class step {

    public static int jumpFloor(int target) {

        if (target <= 1) return 1;
        //最后一次：①跳2  ②跳1
        return jumpFloor(target - 1) + jumpFloor(target - 2);
    }

    public static int jumpFloorV2(int target) {

        int[] dp = new int[50];

        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= target; i++) {
            dp[i] = dp[i - 2] + dp[i - 1];
        }
        return dp[target];
    }

    public static int Solution(int number) {
        int a = 1, b = 1, c = 1;
        for (int i = 2; i <= number; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;

    }


    public static void main(String[] args) {
        System.out.println(jumpFloor(20));
        System.out.println(jumpFloorV2(20));
        System.out.println(Solution(20));
    }

}
